<?php

/**
 * Console log route
 */
class ConsoleLogRoute extends CLogRoute
{
	private $_fd = false;

	public function init()
	{
		parent::init();
		$this->_fd = @fopen('php://stderr', 'w');
	}

	/**
	 * Displays the log messages.
	 * @param array $logs list of log messages
	 */
	public function processLogs($logs)
	{
		if ($this->_fd && Yii::app() instanceof CConsoleApplication) {
			foreach ($logs as $log) {
				$line = @date('m/d H:i:s', $log[3]) . ' [' . strtoupper($log[1]) . '] ' . $log[0] . "\n";
				fwrite($this->_fd, $line);
				fflush($this->_fd);
			}
		}
	}
}
